package org.kfive.nova.hbase;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

import java.io.IOException;

/**
 * Created by admin on 2017-05-14.
 */
public class HbaseWriterReducer extends TableReducer<Text,IntWritable,ImmutableBytesWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values){
            sum+=val.get();
        }
        Put put = new Put(key.getBytes());
        put.addColumn("content".getBytes(),"count".getBytes(),String.valueOf(sum).getBytes());
        context.write(new ImmutableBytesWritable(key.getBytes()),put);
    }
}
